package com.animal.controller;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.animal.dao.ExpManage;
import com.animal.dao.DailyManage;

public class PaperArchiveServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * Constructor of the object.
	 */
	public PaperArchiveServlet() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		
		String dos = request.getParameter("do");
		String id = request.getParameter("id");
		String FileState="纸质档案已归档";
		if (dos == null || dos.equals("")) {
			response.sendRedirect("PaperFileArchive.jsp");
			
		}
		if (dos.equals("expcheck")) {							
			boolean b = ExpManage.updateState(id, FileState);
			
			if(b){
				out.print("<script>alert('纸质档案归档成功!');window.location='PaperFileArchive.jsp';</script>");
			}
			else{
				out.print("<script>alert('纸质档案归档失败!');</script>");
			}
			return;
		}		
		else if(dos.equals("expdel")){
			boolean b = ExpManage.delete(id);
			
			if(b){
				out.print("<script>alert('删除成功!');window.location='PaperFileArchive.jsp';</script>");
				
			}else{
				out.print("<script>alert('删除失败!');</script>");
			}
			return;
		}
		else if (dos.equals("dailycheck")) {							
			boolean b = DailyManage.updateState(id, FileState);
			
			if(b){
				out.print("<script>alert('纸质档案归档成功!');window.location='PaperFileArchive.jsp';</script>");
			}
			else{
				out.print("<script>alert('纸质档案归档失败!');</script>");
			}
			return;
		}
		else if(dos.equals("dailydel")){
			
			boolean b = DailyManage.delete(id);
			
			if(b){
				out.print("<script>alert('删除成功!');window.location='PaperFileArchive.jsp';</script>");
				
			}else{
				out.print("<script>alert('删除失败!');</script>");
			}
			return;
		}
		
		

	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();

		doGet(request,response);
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException { 
		// Put your code here
	}

}